<template>
  <!-- 选择仓库 -->
    <el-dialog title="信息" :visible.sync="openSelectWarehouse" width="1200px" append-to-body :destroy-on-close="true" :before-close="beforeClose">
      <el-form ref="form" @submit.native.prevent :model="formQuery" label-width="100px" :inline="true" v-show="showSearch">
        <el-form-item label="条码" prop="sptm">
          <el-input
            v-model="formQuery.sptm"
            placeholder="请输入条码"
            clearable
            @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="物品规格" prop="spzs">
          <el-input
            v-model="formQuery.spzs"
            placeholder="请输入物品规格"
            clearable
            @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="物品名称" prop="spmc">
          <el-input
            v-model="formQuery.spmc"
            placeholder="请输入物品名称"
            clearable
            @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="品牌" prop="spcd">
          <el-input
            v-model="formQuery.spcd"
            placeholder="请输入品牌"
            clearable
            @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="客户" prop="khmc">
          <el-input
            v-model="formQuery.khmc"
            :disabled="true"
          />
        </el-form-item>
        <el-form-item label="仓库" prop="spckmc">
          <el-select
            v-model="formQuery.spckmc"
            placeholder="请选择"
            clearable
            filterable
            @keyup.enter.native="enterClick"
            :loading="selectWarehouse9Loading"
            :disabled="true"
        >
            <el-option
                v-for="item in selectWarehouseList"
                :key="item.spckid"
                :label="item.spckmc"
                :value="item.spckid"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="柜号" prop="spgh">
          <el-input
            v-model="formQuery.spgh"
            placeholder="请输入柜号"
            clearable
            @keyup.enter.native="enterClick"
          />
        </el-form-item>
        <el-form-item label="批号" prop="spbh">
          <el-input
            v-model="formQuery.spbh"
            placeholder="请输入批号"
            clearable
            @keyup.enter.native="enterClick"
          />
        </el-form-item> 
        <el-form-item>
            <el-button type="primary" size="mini" @click="handleQuery">搜 索</el-button>
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-col :span="1.5">
          <el-button type="primary" plain size="mini" @click="handleExport" :disabled="selection.length === 0">导出勾选数据</el-button>
        </el-col>
      </el-row>
      <el-table
        v-loading="loading"
        :data="warehouseList"
        @selection-change="handleSelectionChange"
        ref="multipleTable"
        @row-click="handleRowClick"
        :row-class-name="tableRowClassName"
      >
        <af-table-column type="selection" width="50" align="center" /> 
        <af-table-column prop="sptm" label="客户条码"  fixed="left"></af-table-column>
        <af-table-column prop="sptmc" label="仓库条码" ></af-table-column>
        <af-table-column prop="spckmc" label="仓库" ></af-table-column>
        <af-table-column prop="ckcw" label="仓位" ></af-table-column>
        <af-table-column prop="spkhmc" label="物品公司" width="250"></af-table-column>
        <af-table-column prop="spjs2" label="件数" ></af-table-column>
        <af-table-column prop="spsl2" label="重量(吨)" ></af-table-column>
        <af-table-column prop="ssrqidn" label="入仓日期" ></af-table-column>
        <af-table-column prop="spdm" label="类型" ></af-table-column>
        <af-table-column prop="change" label="货转次数" ></af-table-column>
        <af-table-column prop="spzs" label="物品规格" ></af-table-column>
        <af-table-column prop="spcd" label="品牌" ></af-table-column>
        <af-table-column prop="spgh" label="柜号" ></af-table-column>
        <af-table-column prop="spbh" label="批号" ></af-table-column>
        <af-table-column prop="wpggA" label="纱支" ></af-table-column>
        <af-table-column prop="wpggB" label="工艺" ></af-table-column>
        <af-table-column prop="wpggC" label="工序" ></af-table-column>
        <af-table-column prop="wpggD" label="用途" ></af-table-column>
        <af-table-column prop="wpggE" label="产地" ></af-table-column>
        <af-table-column prop="wpggF" label="漂染性" ></af-table-column>
        <af-table-column prop="wpggG" label="生产日期" ></af-table-column>
        <af-table-column prop="wpggH" label="颜色" ></af-table-column>
        <af-table-column prop="spjsz" label="质押件数" ></af-table-column>
        <af-table-column prop="spslz" label="质押吨数" ></af-table-column>
      </el-table>
       <pagination
        v-show="total>0"
        :total="total"
        :page.sync="pageNum"
        :limit.sync="pageSize"
        @pagination="getList"
      />
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleSelect">选择</el-button>
      </div>
    </el-dialog>
</template>

<script>
import { selectStock } from "@/api/storage/commonGoods/warehouseMove";
import { selectWarehouse9 } from "@/api/storage/warehouse";

export default {
  name: "WarehouseMoveSelectWarehouse",
  data() {
    return {
      // 显示搜索条件
      showSearch: true,
      //仓库加载
      selectWarehouse9Loading: true,
      //弹窗状态
      openSelectWarehouse: false,
      //列表加载
      loading: true,
      // 查询参数
      formQuery: {
        ckcw: "",
	      ckid: "",
        isBa: "",
        khlx: "",
        khmc: "",
        khmcid: "",
        khpb: 0,
        liid_1: "",
        shopId: 0,
        spbh: "",
        spcd: "",
        spckid: "",
        spckmc:"",
        spckidis: [],
        spcwid2: "",
        spgh: "",
        spmc: "",
        sptm: "",
        spzs: ""
      },
      //勾选数据
      selection:[],
       //excel导出
       exportList: [],
      //选择仓库
      selectWarehouseList: [],
      //行数据
      warehouseList:[],
      //页数
      pageSize: 10,
      //页码
      pageNum:1,
      // 总条数
      total: 0,
    };
  },
  methods: {
    /**获取选择仓库信息 */
    warehouseSelect() {
      this.selectWarehouse9Loading=true
      selectWarehouse9({}).then(response => {
        this.selectWarehouseList = response.data;
        this.selectWarehouse9Loading=false
      });
    },
    /**获取仓库信息 */
    getList() {
      this.loading=true
      selectStock(this.formQuery,{pageNum:this.pageNum, pageSize:this.pageSize}).then(response => {
        this.warehouseList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    /**仓库搜索 */
    handleQuery() {
        this.getList()
    },
    /** 选择录入*/
    handleSelect() {
      this.changeSelectWarehouse()
      this.$emit('warehouseSelected', this.selection)
    },
     // 多选框选中数据
    handleSelectionChange(selection) {
      this.selection = selection
    },
    /**点击列表行触发 */
    handleRowClick(row, column, event) {
      this.$refs.multipleTable.toggleRowSelection(row)
    },
    /**选中行 */
    tableRowClassName({row, rowIndex}) {
      if(this.selection.some((item) => item === row)) {
        return "selected-bg-color"
      }
      return ""
    },
     /** 导出勾选数据*/
    handleExport() {
      if (this.selection.length > 0) {
        let option = {}
        option.fileName = '货物出仓库存勾选数据'
        option.datas = [
          {
            sheetData: this.selection,//数据
            sheetName: 'sheet',
            //表头数据对应的sheetData数据
            sheetFilter: ['spckmc', 'spzs', 'spbh', 'spgh', 'spcd', 'spjs2', 'spjsl', 'spsl2', 'spckmc', 'ckcw', 'ssrqid', 'sptm', 'sptmc', 'spdj', 'spjsz', 'spslz'],
            sheetHeader: [
              //表头数据
              '客户', '物品规格', '批号', '柜号', '品牌', '剩余件数','单重(KG)', '剩余重量(吨)','仓库', '仓位','入仓日期','用户条码','仓库条码','估价单价','质押件数','质押吨数'],
          }
        ]
        let excel = ExportJsonExcel(option)
        excel.saveExcel()
      } else {
        this.$modal.msgError('请勾选数据');
      }
    },
      /**enter键触发 */
    enterClick(e) {
      this.getList()
    },
    /**改变窗口状态 */
    changeSelectWarehouse() {
      this.openSelectWarehouse = !this.openSelectWarehouse;
    },
    /**关闭弹窗 */
    beforeClose(done) {
      this.close()
      done()
    },
    /**关闭弹窗 */
    close() {
      this.changeSelectWarehouse()
    },
    /**打开弹窗 */
    open(inp, data) {
      this.formQuery.ckid = data.spckid
      this.formQuery.khlx = data.khlx
      this.formQuery.khmc = data.khmc
      this.formQuery.spckmc = data.spckmc
      this.formQuery.spckid = data.spckid
      this.formQuery.inp = inp
      this.changeSelectWarehouse()
      this.warehouseSelect()
      this.getList()
    }
  }
};
</script>
